package com.yunxitest.yunxitest.item.audio

import com.yunxitest.yunxitest.Interface.IDetectItem
import com.yunxitest.yunxitest.Interface.IResultCallback
import com.yunxitest.yunxitest.item.audio.`in`.BaseAudioSource
import com.yunxitest.yunxitest.item.audio.`in`.HardwareAudioSource
import com.yunxitest.yunxitest.item.audio.out.AudioOut

class AudioDetectManager(var inResultCallback: IResultCallback?) : IDetectItem {
    var audioOut :AudioOut?=null
    var hardwareAudioSource :HardwareAudioSource?=null
    var lineAudioSource: BaseAudioSource ?=null

    override fun startDetect() {
        audioOut = AudioOut()
        hardwareAudioSource = HardwareAudioSource(audioOut?.queue!!, inResultCallback)
        lineAudioSource= hardwareAudioSource?.lineAudioSource
        startRecord()
        startPlay()
    }

    override fun finish() {
//        stopRecord()
//        stopPlay()
//        release()
    }

    fun startRecord() {
        lineAudioSource?.startRecord()
    }

    fun startPlay() {
        audioOut?.start()
    }


    fun stopRecord() {
        lineAudioSource?.stopRecord()
    }

    fun stopPlay() {
        audioOut?.stop()
    }

    fun release() {
        lineAudioSource?.close()
        hardwareAudioSource?.release()
    }

//    fun setVolumeMax(){
//        am = getSystemService(Context.AUDIO_SERVICE);
//        //获取系统最大音量
//        val maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
//        //获取当前音量
//        val currentVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
//    }

}